Oa.controller('suggestCtrl',function($location,$scope,$http,$sce){
  $scope.totalPage = 1;//全部页数
  $scope.currentPage = 1;//当前页码
  $scope.pageArr;// 页码数组
  $scope.size = 20;
  // 生成页码数组
  $scope.getPage = function(num){
    $scope.pageArr = new Array();
    for(var i=0;i<num;i++){
      $scope.pageArr[i] = i+1;
    }
  }
  //获取   第n页的记录
  $scope.getSuggest = function(num){
    if(num>=1 && num<=$scope.totalPage){
        $http.get(getAllSuggestion_url,
          {
            params:{
              page:num,
              size:$scope.size
            }
          })
        .success(function(res){
          if (res.code==200) {
            $scope.suggest = res.data.list;
            $scope.totalPage = res.data.countPage;
            $scope.currentPage = num;
            $scope.getPage($scope.totalPage);
            $scope.recordsnum = res.data.recordsNum;

            for (var i = 0; i < res.data.list.length; i++) {
            
              $scope.suggest[i].info = $sce.trustAsHtml(res.data.list[i].info);
              console.log($scope.suggest[i].info);
            }

          }else {
            Notify(res.msg,"top-right");
          }
        }).error(function(){
          Notify('客户端错误',"top-right");
      });
    }
  }
  $scope.getRecord = function(){
    $scope.getSuggest($scope.currentPage);
  }
  $scope.getRecord();

  $scope.addSuggestion = function(){
    // e.preventDefault()
    console.log("发表意见");
    $http.post(addSuggestion_url,{
      title:$("input[name='title']").val(),
      info:editor2.txt.html()
    })
    .success(function(res){
      if (res.code==200) {
        Notify(res.msg,"top-right");
        editor2.txt.clear();
        $("input[name='title']").val("")
      }else {
        Notify(res.data,"top-right");
      }
    })
    .error(function(){
      Notify("客户端错误","top-right");
    });
  }

  $scope.showIndex = -1;
  $scope.showInfo = function(i) {
    console.log(i);
    if ($scope.showIndex==i) {
      $scope.showIndex=-1;
    }else {
      $scope.showIndex=i;
    }
  }

});
